package demo.util_ui.client.ui;

import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Generic dialog box
 * @author psriplakich
 *
 */
public class AbstractDialog extends DialogBox {

	protected final DockPanel layoutPanel = new DockPanel();

	/**
	 * can contain buttons.
	 */
	protected final DockPanel bottomPanel = new DockPanel();

	protected DockPanel contentPanel = new DockPanel();

	protected Label statusBar = UIFactory.createLabel("", "label");

	public AbstractDialog() {
		super();

		this.layoutPanel.add(this.contentPanel, DockPanel.CENTER);
		this.layoutPanel.add(this.bottomPanel, DockPanel.SOUTH);

		this.contentPanel.addStyleName("contentPanel");
		this.bottomPanel.addStyleName("bottomPanel");

		this.bottomPanel.add(this.statusBar, DockPanel.CENTER);
		setWidget(this.layoutPanel);

	}

	public DockPanel getBottomPanel() {
		return this.bottomPanel;
	}

	public DockPanel getContentPanel() {
		return this.contentPanel;
	}

	public void putInRootPanel(final String divId) {
		RootPanel.get(divId).add(this);
	}

	public void resetContent(final String title, final String message,
			final String style) {
		setText(title);
		HTML messageLabel = new HTML();
		if (null != style) {
			messageLabel.addStyleName(style);
		}
		messageLabel.addStyleName("message");
		messageLabel.setHTML(message);

		this.contentPanel.clear();
		this.contentPanel.add(messageLabel, DockPanel.CENTER);
	}

	public void showError(final String title, final String message) {
		showMessage(title, message, "serverResponseLabelError");
	}

	public void showInfo(final String title, final String message) {
		showMessage(title, message, null);
	}

	public void showMessage(final String title, final String message,
			final String style) {
		resetContent(title, message, style);
		center();
	}

}
